<?php

namespace App\Http\Controllers\UserApi;

use App\Http\Controllers\Controller;
use Illuminate\Http\Request;
use App\Services\Api\UserTrainServices;
use App\Models\UserTrain;
use App\Models\UserSubscribe;

class UserTrainContoller extends BaseController
{
    public function user_train(UserTrainServices $trainServices,UserTrain $userTrain){
        $member_id = auth('api') -> user()->id;
        //$data = $trainServices->user_train();
        $data = $userTrain->where('user_id',$member_id)->paginate();
        return $this->success($data);
    }

    public function sign_train(Request $request,UserTrain $userTrain,UserSubscribe $subscribe){
        $subscribe = $subscribe->WhereID($request->input('subscribe_id'))->first();
        //dd($subscribe);
        $res = $userTrain->insert([
            'user_id'=>auth('api') -> user()->id,
            'class_base_id'=>$subscribe->class_base_id,
            'teacher_id'=>$subscribe->teacher_id,
            'store_id'=>$subscribe->store_id,
            //'train_time',
            'created_at'=>date("Y-m-d H:i:s"),
        ]);
        if($res){
            return $this->success();
        }
        return $this->fail('保存失败');
    }
}
